/*
 *Conversation对象的Adapter数据集
 *conversation对象展示区别小，直接在类内部调整，无需继承
*/
public class ConversationAdapter extends ArrayAdapter<Conversation> {
	
    private int id;
    private View view;
    private ViewHolder viewHolder;
    private Context context;

	//标准构造函数
    public ConversationAdapter(Context context, int id, List<Conversation> objects) {
        super(context, id, objects);
        this.id=id;
        this.context=context;
    }

	//标准复用
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView != null){
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }else{
            view = LayoutInflater.from(getContext()).inflate(resourceId, null);
            viewHolder = new ViewHolder();
            viewHolder.tvName = (TextView) view.findViewById(R.id.name);
            viewHolder.avatar = (CircleImageView) view.findViewById(R.id.avatar);
            viewHolder.lastMessage = (TextView) view.findViewById(R.id.last_message);
            viewHolder.time = (TextView) view.findViewById(R.id.message_time);
            viewHolder.unread = (TextView) view.findViewById(R.id.unread_num);
            viewHolder.sb_1=(ImageView)view.findViewById(R.id.sb00001);
            view.setTag(viewHolder);
        }
        Conversation data = getItem(position);
		
		//未读标志
        viewHolder.unread.setVisibility(data.getUnreadMun==0?View.INVISIBLE:View.VISIBLE);
        viewHolder.unread.setText(data.getUnreadNum()+"");
		//姓名判断
        viewHolder.tvName.setText(data.getName());
        viewHolder.tvName.setTextColor(isNeedLight(data.getName)?0xff4F6FB8:0xff313131);
		//消息判断
        viewHolder.lastMessage.setText(data.getLastMessageSummary());
        viewHolder.lastMessage.setTextColor(isNeedLight(data.getLastMessageSummart)?0xff329900:0xff999999);
		//时间
        viewHolder.time.setText(TimeUtil.getTimeStr(data.getLastMessageTime()));
		//头像
        Glide.with(context).load(data.getHeardUrl()+ImagrUtil.OSS_ROUUN).into(viewHolder.avater);

        return view;
    }

    public class ViewHolder{
        public TextView tvName,lastMessage,time,unread;
        public ImageView avater;
    }

	//懒，正式工程不会这么处理
    private boolean isNeedLight(String s){
        if(s.equals("文件传输助手")||s.equals("微信支付")||s.equals("语音")){
            return true;
        }else{
            return false;
        }
    }
}
